package de.laures.cewolf.style;

import java.awt.Shape;
import java.awt.geom.Ellipse2D;

public class ShapeFactory implements ShapeConstants {
	public static final Shape createShape(String type) {
		Shape shape;
		switch (getShapeTypeConstant(type)) {
		case CIRCLE:
			shape = new Ellipse2D.Double(-4.5D, -4.5D, 9D, 9D);
			return shape;

		default:
			throw new RuntimeException("unsupported shape type " + type);
		}
	}

	public static final Shape createShape(String type, float stokeWidth) {
		double x = -stokeWidth * 2, y = -stokeWidth * 2;
		double w = stokeWidth * 4, h = stokeWidth * 4;
		Shape shape;
		switch (getShapeTypeConstant(type)) {
		case CIRCLE:
			shape = new Ellipse2D.Double(x, y, w, h);
			return shape;

		default:
			throw new RuntimeException("unsupported shape type " + type);
		}
	}

	private static final int getShapeTypeConstant(String type) {
		int res = ShapeTypes.typeList.indexOf(type.toLowerCase());
		if (res < 0) {
			throw new RuntimeException("unsupported shape type " + type);
		}
		return res;
	}
}
